<include file="Public/min-header"/>
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";
</script>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"/>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.all.js"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css"/>
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content ">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right" style="margin: 5px">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default"
                   data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 添加秒杀商品 </h3>
                </div>
                <div class="panel-body ">
                    <!--表单数据-->
                    <form method="post" id="promotion" action="">
                        <!--通用信息-->
                        <div class="tab-content col-md-10">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                    <tr>
                                        <td>选择商品:</td>
                                        <td>
                                            <div class="form-group">
                                                <div class="col-xs-2">
                                                    <a class="btn btn-primary" href="javascript:void(0);"
                                                       onclick="selectGoods()"><i class="fa fa-search"></i>添加商品</a>
                                                </div>
                                                <div class="col-xs-2">
                                                    <span id="err_goods"
                                                          style="color:#F00; display:none;">请添加秒杀商品</span>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <div class="form-group">
                                                <table class="table table-bordered">
                                                    <thead>
                                                    <tr>
                                                        <th style="display:none">选择</th>
                                                        <th class="text-left">商品名称</th>
                                                        <th class="text-left">价格</th>
                                                        <th class="text-left">库存</th>
                                                        <th class="text-left">操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="goods_list">
                                                    <foreach name="prom_goods" item="vo">
                                                        <tr>
                                                            <td style="display:none">
                                                                <input type="checkbox"
                                                                       name="goods_id[]"
                                                                       checked="checked"
                                                                       value="{$vo.goods_id}"/>
                                                            </td>
                                                            <td class="text-left">{$vo.goods_name}</td>
                                                            <td class="text-left">{$vo.shop_price}</td>
                                                            <td class="text-left">{$vo.store_count}</td>


                                                            <td class="text-left"><a href="javascript:void(0)"
                                                                                     onclick="javascript:$(this).parent().parent().remove();">删除</a>
                                                            </td>
                                                        </tr>
                                                    </foreach>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>开放时间：</td>
                                        <td>
                                            <?php for ($i = 0; $i < 24; $i++): ?>
                                            <label class="custom-control custom-checkbox" style="margin-right: 10px">
                                                <input name="open_time[]" <?= is_array($open_time) && in_array($i,
                                    $open_time) ? 'checked' : null ?>
                                                value="<?= $i ?>"
                                                type="checkbox" class="custom-control-input">
                                                <span class="custom-control-indicator"></span>
                                                <span class="custom-control-description"><?= $i < 10 ? '0' . $i : $i ?>
                                                    :00~<?= $i < 10 ? '0' . $i : $i ?>:59</span>
                                            </label>
                                            <?php endfor; ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>开始时间：</td>
                                        <td>
                                            <input type="text" class="form-control" id="start_time" name="start_time"
                                                   value="{$info.start_time}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>结束时间：</td>
                                        <td>
                                            <input type="text" class="form-control" id="end_time" name="end_time"
                                                   value="{$info.end_time}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>* 限购数量</td>
                                        <td>
                                            <input name="buy_max" placeholder="请填写整数值"
                                            class="form-control mr-3"
                                            type="number" step="1" min="0"
                                            <?= $modal->buy_max != 0 ? null : 'checked' ?>
                                            value="0" style="width:300px;">
                                            <label class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input no-buy-max">
                                                <span class="custom-control-indicator"></span>
                                                <span class="custom-control-description">不限购</span>
                                            </label>
                                            <div class="text-muted fs-sm">每个订单限制购买数量，填写0表示不限购，默认不限购</div>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>* 限单</td>
                                        <td>
                                            <input name="buy_limit" placeholder="请填写整数值"
                                            class="form-control mr-3"
                                            type="number" step="1" min="0"
                                            <?= $modal->buy_limit != 0 ? null : 'checked' ?>
                                            value="0" style="width:300px;">
                                            <label class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input no-buy-limit">
                                                <span class="custom-control-indicator"></span>
                                                <span class="custom-control-description">不限单</span>
                                            </label>
                                            <div class="text-muted fs-sm">活动限购订单数，填写0表示不限单，默认不限单</div>
                                        </td>
                                    </tr>

                                    <!--<tr>-->
                                        <!--<td>适合用户范围：</td>-->
                                        <!--<td>-->
                                            <!--<foreach name="level" item="vo">-->
                                                <!--<input type="checkbox"-->
                                                <!--<if condition="strripos($info['group'],$vo['level_id']) nheq false">-->
                                                    <!--checked-->
                                                <!--</if>-->
                                                <!--name="group[]" value="{$vo.level_id}">{$vo.level_name}-->
                                            <!--</foreach>-->
                                        <!--</td>-->
                                    <!--</tr>-->
                                    <tr>
                                        <td class="col-sm-2">活动描述：</td>
                                        <td class="col-sm-8">
							        <textarea class="span12 ckeditor" id="post_content" name="description" title="">
							            {$info.description}
							        </textarea>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td><input class="btn btn-default" type="reset" value="重置">
                                            <input type="hidden" name="id" value="{$info.id}">
                                        </td>
                                        <td class="text-right"><input class="btn btn-primary" type="button"
                                                                      onclick="adsubmit()" value="保存"></td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </form><!--表单数据-->
                </div>
            </div>
        </div>
    </section>
</div>
<script>

    var editor;
    $(function () {
        //具体参数配置在  editor_config.js 中
        var options = {
            zIndex: 999,
            initialFrameWidth: "100%", //初化宽度
            initialFrameHeight: 350, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
            pasteplain: true, autoHeightEnabled: true,
            autotypeset: {
                mergeEmptyline: true,        //合并空行
                removeClass: true,           //去掉冗余的class
                removeEmptyline: false,      //去掉空行
                textAlign: "left",           //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
                imageBlockLine: 'center',    //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
                pasteFilter: false,          //根据规则过滤没事粘贴进来的内容
                clearFontSize: false,        //去掉所有的内嵌字号，使用编辑器默认的字号
                clearFontFamily: false,      //去掉所有的内嵌字体，使用编辑器默认的字体
                removeEmptyNode: false,      //去掉空节点
                removeTagNames: {"font": 1},
                indent: false,               // 行首缩进
                indentValue: '0em'           //行首缩进的大小
            },
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo', 'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace']
            ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("post_content");
    });

    function adsubmit() {

        var pg = [];
        //过滤选择重复商品
        $('input[name*="goods_id"]').each(function (i, o) {
            pg.push($(o).val());
        });
        if (pg.length == 0) {
            layer.msg('请选择商品');
            return false;
        }
        $('#promotion').submit();
    }

    function selectGoods() {
        var goods_id = [];
        //过滤选择重复商品
        $('input[name*="goods_id"]').each(function (i, o) {
            goods_id.push($(o).val());
        });
        var url = '/index.php?m=Seller&c=Promotion&a=search_goods&goods_id=' + goods_id + '&t=' + Math.random();
        layer.open({
            type: 2,
            title: '选择商品',
            shadeClose: true,
            shade: 0.3,
            area: ['70%', '80%'],
            content: url,
        });
    }

    function call_back(table_html) {
        layer.closeAll('iframe');
        $('#goods_list').append(table_html);
    }



    $(document).ready(function () {
        $("#prom_type").trigger('change');
        $('input[name=expression]').val("{$info.expression}");

        $('#start_time').daterangepicker({
            format: "YYYY-MM-DD",
            singleDatePicker: true,
            showDropdowns: true,
            minDate: '{$min_date}',
            maxDate: '2030-01-01',
            startDate: '{$min_date}',
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });

        $('#end_time').daterangepicker({
            format: "YYYY-MM-DD",
            singleDatePicker: true,
            showDropdowns: true,
            minDate: '{$min_date}',
            maxDate: '2030-01-01',
            startDate: '{$min_date}',
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });
    })
</script>
</body>
</html>